package com.yiyukongjian.house.dataaccess;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import com.yiyukongjian.house.HouseConstants;

final class HouseInforDataAccessorMockImpl implements HouseInforDataAccessor {

	@Override
	public HashMap<String, ?> queryGeneralHouseInformation(Map<String, String> queryCondition){
		HashMap queryResult = new HashMap();
		if(queryCondition.containsKey(HouseConstants.KEY_QUERY_FROM)){
			String queryFrom = queryCondition.get(HouseConstants.KEY_QUERY_FROM);
			if(Integer.parseInt(queryFrom) == 0){				
				int r = new Random().nextInt(10);
				System.out.println("生成的随机数为 ： " + r);
				if(r >= 2){//模拟查询成功并有数据返回
					List result = new ArrayList();
					Map temp = null;
					for(int i = 0; i < 10; i++){
						temp = new HashMap();
						temp.put(HouseConstants.KEY_ID, i + "");
						temp.put(HouseConstants.KEY_FWDZ, "房屋地址 " + i);
						temp.put(HouseConstants.KEY_FZXM, "房主姓名 " + i);
						temp.put(HouseConstants.KEY_FZZJHM, "房主证件号码 " + i);
						temp.put(HouseConstants.KEY_FZLXDH, "房主联系电话 " + i);
						temp.put(HouseConstants.KEY_CZRXM, "承租人姓名 " + i);
						temp.put(HouseConstants.KEY_CZRZJHM, "承租人证件号码 " + i);
						temp.put(HouseConstants.KEY_CZRLXDH, "承租人联系电话 " + i);
//						temp.put(HouseConstants.KEY_DJRQ, "登记日期 " + i);
						temp.put(HouseConstants.KEY_QZRQ, "起租日期 " + i);
						temp.put(HouseConstants.KEY_TZRQ, "停租日期 " + i);
						temp.put(HouseConstants.KEY_DJRXM, "登记人姓名 " + i);
						result.add(temp);
					}
					queryResult.put("success", result);
				}else if(r == 0){//模拟查询失败超时 0.1几率
					queryResult.put("error", "查询失败，您现在的网络情况不太好哦。");
				}else if(r == 1){//模拟由于服务器原因查询失败 0.1几率
					queryResult.put("error", "查询失败，数据源错误。");
				}
			}else{
				//在某结果上继续查询
				System.out.println("继续加载");
				int r = new Random().nextInt(10) + Integer.parseInt(queryFrom);
				System.out.println("生成的随机数为 ： " + r);
				if(r >= Integer.parseInt(queryFrom) + 2){
					List result = new ArrayList();
					Map temp = null;
					for(int i = Integer.parseInt(queryFrom); i < Integer.parseInt(queryFrom) + 10; i++){
						temp = new HashMap();
						temp.put(HouseConstants.KEY_ID, i + "");
						temp.put(HouseConstants.KEY_FWDZ, "房屋地址More" + i);
						temp.put(HouseConstants.KEY_FZXM, "房主姓名More " + i);
						temp.put(HouseConstants.KEY_FZZJHM, "房主证件号码More " + i);
						temp.put(HouseConstants.KEY_FZLXDH, "房主联系电话More " + i);
						temp.put(HouseConstants.KEY_CZRXM, "承租人姓名More " + i);
						temp.put(HouseConstants.KEY_CZRZJHM, "承租人证件号码More " + i);
						temp.put(HouseConstants.KEY_CZRLXDH, "承租人联系电话More " + i);
//						temp.put(HouseConstants.KEY_DJRQ, "登记日期 " + i);
						temp.put(HouseConstants.KEY_QZRQ, "起租日期More " + i);
						temp.put(HouseConstants.KEY_TZRQ, "停租日期More " + i);
						temp.put(HouseConstants.KEY_DJRXM, "登记人姓名More " + i);
						result.add(temp);
					}
					queryResult.put("success", result);
				}else if(r == Integer.parseInt(queryFrom) + 0){//模拟查询失败超时 0.1几率
					queryResult.put("error", "查询失败，您现在的网络情况不太好哦。");
				}else if(r == Integer.parseInt(queryFrom) + 1){//模拟由于服务器原因查询失败 0.1几率
					queryResult.put("error", "查询失败，数据源错误。");
				}
			}
		}
		System.out.println("AA" + queryResult);
		return queryResult;
	}
}
